<?php

namespace hiduoke\services\formBuilder\traits;

use FormBuilder\UI\Elm\Components\Input;
use FormBuilder\UI\Elm\Components\InputNumber;
use hiduoke\services\formBuilder\element\DkTagTextarea;
use hiduoke\services\formBuilder\form\DkAddonGroupSelect;
use hiduoke\services\formBuilder\form\DkAddonSelect;
use hiduoke\services\formBuilder\form\DkColorInput;
use hiduoke\services\formBuilder\form\DkGroup;
use hiduoke\services\formBuilder\form\DkIconInput;
use hiduoke\services\formBuilder\form\DkMenuTree;
use hiduoke\services\formBuilder\form\DkObject;
use hiduoke\services\formBuilder\form\DkSelect;
use hiduoke\services\formBuilder\form\DkTinyEditor;
use hiduoke\services\formBuilder\form\DkTypeInput;
use hiduoke\services\formBuilder\form\DkUrlInput;
use hiduoke\services\formBuilder\show\DkCopyInput;

trait DkForm
{
    /**
     * 菜单树选择器
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkMenuTree
     */
    public static function dkMenuTree($field, $title, $value = [])
    {
        return new DkMenuTree($field, $title, $value);
    }

    /**
     * 链接输入框
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkUrlInput
     */
    public static function dkUrlInput($field, $title, $value = ''){
        return new DkUrlInput($field, $title, $value);
    }

    /**
     * 颜色选择器
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkColorInput
     */
    public static function dkColorInput($field, $title, $value = '')
    {
        return new DkColorInput($field, $title, $value);
    }

    /**
     * 子表单组件
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkGroup
     */
    public static function dkGroup($field, $title, $value = [])
    {
        return new DkGroup($field, $title, $value);
    }

    /**
     * 对象
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkObject
     */
    public static function dkObject($field, $title, $value = [])
    {
        return new DkObject($field, $title, $value);
    }

    /**
     * 复制输入框
     * @param $field
     * @param $title
     * @param string $value
     * @return DkCopyInput
     */
    public static function dkCopyInput($field, $title, $value = '')
    {
        return new DkCopyInput($field, $title, $value);
    }

    /**
     * 下拉选择组件
     *
     * @param string $field
     * @param string $title
     * @param mixed $value
     * @return DkSelect
     */
    public static function dkSelect($field, $title, $value = '')
    {
        $multiple = is_array($value) ? true : false;
        $select = new DkSelect($field, $title, $value);
        $select->multiple($multiple);
        return $select;
    }

    /**
     * 多选
     *
     * @param string $field
     * @param string $title
     * @param array $value
     * @return DkSelect
     */
    public static function dkSelectMultiple($field, $title, array $value = [])
    {
        return self::dkSelect($field, $title, $value);
    }

    /**
     * 应用组应用选择器
     * @param $field
     * @param $title
     * @param string $value
     * @return DkAddonSelect
     */
    public static function dkAddonSelect($field, $title, $value = '')
    {
        $component = new DkAddonSelect($field, $title, $value);
        return $component;
    }

    /**
     * 应用组选择器
     * @param $field
     * @param $title
     * @param string $value
     * @return DkAddonGroupSelect
     */
    public static function dkAddonGroupSelect($field, $title, $value = '')
    {
        $component = new DkAddonGroupSelect($field, $title, $value);
        return $component;
    }


    public static function dkTypeInput($field, $title, $value = '')
    {
        $input = new DkTypeInput($field, $title, $value);
        return $input;
    }

    /**
     * 富文本编辑器
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkTinyEditor
     */
    public static function dkTinyEditor($field, $title, $value = '')
    {
        $input = new DkTinyEditor($field, $title, $value);
        return $input;
    }

    /**
     * 标签输入框
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkTagTextarea
     */
    public static function dkTagTextarea($field, $title, $value = [])
    {
        $DkTagTextarea = new DkTagTextarea($field, $title,$value);
        return $DkTagTextarea;
    }

    /**
     * 图标选择器
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @return DkIconInput
     */
    public static function dkIconInput($field, $title, $value = '')
    {
        $DkIconInput = new DkIconInput($field, $title, (string)$value);
        return $DkIconInput;
    }

    /**
     * 输入框
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @param $help
     * @param $type
     * @return Input
     */
    public static function dkInput($field, $title, $value = '', $help = '', $type = Input::TYPE_TEXT)
    {
        $input = new Input($field, $title, (string)$value);
        if ($help) {
            $help = is_string($help) ? [$help] : $help;
            return $input->type($type)->appendRule('suffix', ['type' => 'p', 'class' => 'form-help', 'children' => $help]);
        } else {
            return $input->type($type);
        }
    }

    /**
     * 数字输入框
     * Create by :  刘泓宾<514660094@qq.com>
     * @param $field
     * @param $title
     * @param $value
     * @param $help
     * @return InputNumber
     */
    public static function dkInputNumber($field, $title, $value = '', $help = '')
    {
        $inputNumber = new inputNumber($field, $title, $value);
        if ($help) {
            $help = is_string($help) ? [$help] : $help;
            return $inputNumber->appendRule('suffix', ['type' => 'p', 'class' => 'form-help', 'children' => $help]);
        } else {
            return $inputNumber;
        }
    }
}
